package com.weic.flink.datastream.source

import org.apache.flink.api.scala.ExecutionEnvironment
import org.apache.flink.streaming._
import org.apache.flink.streaming.api.scala._

/**
 * @Auther:BigData-weic
 * @ClassName:Demo01FlinkWordCount
 * @Date:2020/12/16 20:55
 * @功能描述: $FunctionDescription
 * @Version:1.0
 */
object Demo01FlinkWordCount {
	def main(args: Array[String]): Unit = {
		val env = StreamExecutionEnvironment.getExecutionEnvironment
		//创建流数据
		val lines = env.socketTextStream("node-1",9999)
		//对流数据进行处理
		val ret = lines.flatMap(_.split("\\s+"))
			.map(word => WordCount(word, 1))
			.keyBy("word")
			.sum("count")
		ret.print("WordCount:::")
		env.execute(s"${Demo01FlinkWordCount.getClass.getSimpleName}")
	}
}
case class WordCount(word:String,count:Int)
